﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LightSwitchApplication
{
    public class FavoritesController : BasicController
    {
        // GET api/<controller>
        public object Get() //IEnumerable<string>
        {
            var result = (from f in DataWorkspace.MMC_Content.Favorites.GetQuery().Execute()
                select new { Id = f.Id
                , CarId = (f.Car == null ? 0 : f.Car.Id)
                , PlaceId = (f.Place == null ? 0 : f.Place.Id)
                });
            return result;
        }

        // GET api/<controller>/5
        public object Get(int id)
        {
            return (from f in DataWorkspace.MMC_Content.Favorites.GetQuery().Execute() where f.Id == id
                select new { Id = f.Id
                        , CarId = (f.Car == null ? 0 : f.Car.Id)
                        , PlaceId = (f.Place == null ? 0 : f.Place.Id)
                }).FirstOrDefault();
        }

        //// POST api/<controller>
        //public void Post([FromBody]string value)
        //{
        //}

        //// PUT api/<controller>/5
        //public void Put(int id, [FromBody]string value)
        //{
        //}

        //// DELETE api/<controller>/5
        //public void Delete(int id)
        //{
        //    var place = DataWorkspace.MMC_Content.Favorites_SingleOrDefault(id);
        //    if (place != null)
        //    {
        //        place.Delete();
        //        DataWorkspace.MMC_Content.SaveChanges();
        //    }
        //}
    }
}